<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/14
 * Time: 13:36
 *
 * @copyright: ©2024 永州 微聚商网络科技有限公司
 * @link: https://www.wEijuyunke.com
 */

namespace app\admin\controller;
use app\admin\model\Config as ConfigModel;
use app\admin\model\Timing;
use app\Request;

class  Config{
    public function  index(){
        $configModel = new \app\home\model\Config();
        $configList = $configModel->select()->toArray();
        $configList = array_column($configList, 'value', 'key');
        return adminSuccess('配置', $configList);
    }

    public function edit(Request $request){
        $param = $request->param();
        $configModel = new \app\home\model\Config();
        foreach ($param as $key => $value) {
            $configModel->where(['key' => $key])->update(['value' => $value]);
        }
        return adminSuccess('修改成功');
    }

    public function Timing(){
        $TimingModel  = new Timing();
        $data =  $TimingModel->select()->toArray();
        $count =  $TimingModel->count();

        $dir  =   $sql = str_replace("/public", "", $_SERVER['DOCUMENT_ROOT'] );
        foreach ($data as $key =>  $value){
            $data[$key]['link'] ='php'.  $dir.$value['link'];
        }
        return adminSuccess('',['list'=>$data,'count'=>$count ]);
    }
}
